package foundation.递归;

import java.util.ArrayList;
import java.util.List;

/**
 * @author hang an
 * @since 2025/7/13
 */
public class 子集 {
    private List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        f(nums, 0, new ArrayList<>());
        return res;
    }

    public void f(int[] nums, int index, List<Integer> path) {
        if (nums.length == index) {
            res.add(new ArrayList<>(path));
        } else {
            path.add(nums[index]);
            f(nums, index + 1, path);
            path.remove(path.size() - 1);
            f(nums, index + 1, path);
        }
    }
}
